package com.kunya.product.controller.portall;

import com.kunya.common.common.ServerResponse;
import com.kunya.product.po.Address;
import com.kunya.product.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author WangGang
 * @Description: 收货地址controller
 * @date 2018/7/18 9:24
 */
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private IAddressService iAddressService;

    /**
     * @Author WangGang
     * @Description 新增收货地址
     * @Date 9:25 2018/7/18
     **/
    @RequestMapping(value = "/insertAddress",method = RequestMethod.POST)
    public ServerResponse<Address> insertAddress(Long userId, Address address, HttpServletRequest httpServletRequest){
        return iAddressService.insertAddress(userId,address,"340_");
    }
    /**
     * @Author WangGang
     * @Description 根据用户id查询收货地址列表
     * @Date 10:24 2018/7/18
     **/
    @RequestMapping(value = "/selectAddressListByUserId",method = RequestMethod.GET)
    public ServerResponse<List<Address>> selectAddressByUserId(Long userId,HttpServletRequest httpServletRequest){
        return iAddressService.selectAddressListByUserId(userId,"340_");
    }
    /**
     * @Author WangGang
     * @Description 根据收货地址id和用户id查询收货地址详情
     * @Date 11:03 2018/7/18
     **/
    @RequestMapping(value = "/selectAddress",method = RequestMethod.GET)
    public ServerResponse selectAddress(Long addressId,Long userId,HttpServletRequest httpServletRequest){
        return iAddressService.selectAddress(addressId,userId,"340_");
    }
    /**
     * @Author WangGang
     * @Description 根据收货地址id编辑收货地址
     * @Date 13:46 2018/7/18
     **/
    @RequestMapping(value = "/updateAddress",method = RequestMethod.POST)
    public ServerResponse updateAddress(Long addressId,Address address,HttpServletRequest httpServletRequest){
        return iAddressService.updateAddress(addressId,address,"340_");
    }

    /**
     * @author zhangjiaqing
     * @Description: 删除收货地址
     * @param
     * @date 2018/7/18 13:37
     */
    @RequestMapping("/removeAddress")
    public ServerResponse removeAddress(Long addressId, HttpServletRequest httpServletRequest){
        return iAddressService.removeAddress(addressId,"340_");
    }

    /**
     * @author zhangjiaqing
     * @Description: 设置默认收货地址
     * @param
     * @date 2018/7/18 13:42
     */
    @RequestMapping("/setDefaultAddress")
    public ServerResponse setDefaultAddress(Long userId, Long addressId, Boolean defaults, HttpServletRequest httpServletRequest){
        return iAddressService.setDefaultAddress(userId,addressId,defaults,"340_");
    }

}
